{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Row With Maximum Ones"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #array #matrix"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数组 #矩阵"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: rowAndMaximumOnes"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #一最多的行"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个大小为 <code>m x n</code> 的二进制矩阵 <code>mat</code> ，请你找出包含最多 <strong>1</strong> 的行的下标（从 <strong>0</strong> 开始）以及这一行中 <strong>1</strong> 的数目。</p>\n",
    "\n",
    "<p>如果有多行包含最多的 1 ，只需要选择 <strong>行下标最小</strong> 的那一行。</p>\n",
    "\n",
    "<p>返回一个由行下标和该行中 1 的数量组成的数组。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>mat = [[0,1],[1,0]]\n",
    "<strong>输出：</strong>[0,1]\n",
    "<strong>解释：</strong>两行中 1 的数量相同。所以返回下标最小的行，下标为 0 。该行 1 的数量为 1 。所以，答案为 [0,1] 。 \n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>mat = [[0,0,0],[0,1,1]]\n",
    "<strong>输出：</strong>[1,2]\n",
    "<strong>解释：</strong>下标为 1 的行中 1 的数量最多<code>。</code>该行 1 的数量<code>为 2 。所以，答案为</code> [1,2] 。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 3：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>mat = [[0,0],[1,1],[0,0]]\n",
    "<strong>输出：</strong>[1,2]\n",
    "<strong>解释：</strong>下标为 1 的行中 1 的数量最多。该行 1 的数量<code>为 2 。所以，答案为</code> [1,2] 。</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>m == mat.length</code>&nbsp;</li>\n",
    "\t<li><code>n == mat[i].length</code>&nbsp;</li>\n",
    "\t<li><code>1 &lt;= m, n &lt;= 100</code>&nbsp;</li>\n",
    "\t<li><code>mat[i][j]</code> 为 <code>0</code> 或 <code>1</code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [row-with-maximum-ones](https://leetcode.cn/problems/row-with-maximum-ones/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [row-with-maximum-ones](https://leetcode.cn/problems/row-with-maximum-ones/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['[[0,1],[1,0]]', '[[0,0,0],[0,1,1]]', '[[0,0],[1,1],[0,0]]']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        idx = mx = 0\n",
    "        for i, row in enumerate(mat):\n",
    "            x = Counter(row)[1]\n",
    "            if x > mx:\n",
    "                idx, mx = i, x\n",
    "        return [idx, mx]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        ans,oneCount = 0,mat[0].count(1)\n",
    "        for i in range(1,len(mat)):\n",
    "            if mat[i].count(1) > oneCount:\n",
    "                oneCount = mat[i].count(1)\n",
    "                ans = i\n",
    "        return [ans,oneCount]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        m, n = len(mat), len(mat[0])\n",
    "        r = [0, 0]\n",
    "        for i in range(m):\n",
    "            if mat[i].count(1) > r[1]:\n",
    "                r[0] = i \n",
    "                r[1] = mat[i].count(1)\n",
    "\n",
    "        return r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        row = cnt = 0\n",
    "        for i in range(len(mat)):\n",
    "            m = sum(mat[i])\n",
    "            if m > cnt:\n",
    "                row = i\n",
    "                cnt = m\n",
    "        return row, cnt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        res = [row.count(1) for row in mat]\n",
    "        mx = max(res)\n",
    "        i = res.index(mx)\n",
    "        return [i, mx]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        count_1 = 0 \n",
    "        res = 0\n",
    "        for index,i in enumerate(mat):\n",
    "            tem = count_1\n",
    "            count_1 = max(count_1,i.count(1))\n",
    "            if tem != count_1:\n",
    "                res = index\n",
    "        return [res,count_1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        hash = {}\n",
    "        l = len(mat)\n",
    "        flag = 0\n",
    "        for x in range(l):\n",
    "            ones = mat[x].count(1)\n",
    "            if ones not in hash:\n",
    "                hash[ones] = x\n",
    "        m = max(hash)\n",
    "        return [hash[m], m]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        row_num, one_num = -1, -1\n",
    "        m, n = len(mat), len(mat[0])\n",
    "        for i in range(m):\n",
    "            tmp_num = 0\n",
    "            for j in range(n):\n",
    "                if mat[i][j]: tmp_num += 1\n",
    "            if tmp_num > one_num:\n",
    "                one_num = tmp_num\n",
    "                row_num = i\n",
    "        return [row_num, one_num]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\r\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\r\n",
    "        a = [sum(x) for x in mat]\r\n",
    "        b = max(a)\r\n",
    "        for i in range(len(a)):\r\n",
    "            if a[i] == b:\r\n",
    "                return [i, b]\r\n",
    "        return [0, 0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        m = len(mat)\n",
    "        n = len(mat[0])\n",
    "        maxrow = -1\n",
    "        maxx = -1\n",
    "        for i in range(m):\n",
    "            x = 0\n",
    "            for j in range(n):\n",
    "                x += mat[i][j]\n",
    "            if x > maxx:\n",
    "                maxrow = i\n",
    "                maxx = x\n",
    "        return [maxrow, maxx]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        # res = [0, 0]\n",
    "        # for i, m in enumerate(mat):\n",
    "        #     cur = m.count(1)\n",
    "        #     if cur > res[1]:\n",
    "        #         res = [i, cur]\n",
    "        # return res\n",
    "\n",
    "        # --------------\n",
    "        max_sum, idx = -1, 0\n",
    "        for i, row in enumerate(mat):\n",
    "            s = sum(row)\n",
    "            if s > max_sum:\n",
    "                max_sum, idx = s, i\n",
    "        return [idx, max_sum]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        row_i, max_count = 0, 0\n",
    "        for i in range(len(mat)):\n",
    "            new_count = mat[i].count(1)\n",
    "            if new_count > max_count:\n",
    "                row_i = i\n",
    "                max_count = new_count\n",
    "        return row_i, max_count\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        maxct = 0\n",
    "        idx = 0\n",
    "        i = 0\n",
    "        for row in mat:\n",
    "            cnt = 0\n",
    "            for cell in row:\n",
    "                cnt += cell\n",
    "            if cnt > maxct:\n",
    "                maxct = cnt\n",
    "                idx = i \n",
    "            i += 1\n",
    "        return [idx, maxct]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        m =len(mat)\n",
    "        n=len(mat[0])\n",
    "        maxrow=-1\n",
    "        maxx=-1\n",
    "        for i in range(m):\n",
    "            x=0\n",
    "            for j in range(n):\n",
    "                x+=mat[i][j]\n",
    "            if x >maxx:\n",
    "                maxrow=i\n",
    "                maxx=x\n",
    "        return [maxrow,maxx]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    \n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        idx, num = 0, 0\n",
    "        for i, line in enumerate(mat):\n",
    "            tmp = sum(line)\n",
    "            if tmp > num:\n",
    "                idx = i\n",
    "                num = tmp\n",
    "                \n",
    "        return [idx, num]\n",
    "            \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        m = len(mat)\n",
    "        n = len(mat[0])\n",
    "\n",
    "        idx = 0\n",
    "        res = 0\n",
    "        num = 0\n",
    "        for i in range(m):\n",
    "            num = 0\n",
    "            for j in range(n):\n",
    "                num += mat[i][j]\n",
    "                if num + (n - j - 1) < res:\n",
    "                    break\n",
    "            if num > res:\n",
    "                res = num\n",
    "                idx = i \n",
    "        \n",
    "        return [idx, res]\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        l_max = []\n",
    "        for i in range(len(mat)):\n",
    "            l_max.append(mat[i].count(1))\n",
    "\n",
    "        return [l_max.index(max(l_max)), max(l_max)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        index = 0\n",
    "        cnt = 0\n",
    "\n",
    "        for i in range(len(mat)):\n",
    "            cur = sum(filter(lambda x: x == 1, mat[i]))\n",
    "            if cur > cnt:\n",
    "                index = i\n",
    "                cnt = cur\n",
    "        return [index, cnt]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        a,b=0,0\n",
    "        for i,x in enumerate(mat):\n",
    "            y=x.count(1)\n",
    "            if y>b:\n",
    "                b=y\n",
    "                a=i\n",
    "        return [a,b]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        max_sum, idx = -1, 0\n",
    "        for i, row in enumerate(mat):\n",
    "            s = sum(row)\n",
    "            if s > max_sum:\n",
    "                max_sum, idx = s, i\n",
    "        return [idx, max_sum]\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        n1max=0\n",
    "        mmax=0\n",
    "        for i in range(len(mat)):\n",
    "            n1=mat[i].count(1)\n",
    "            if n1>n1max:\n",
    "                n1max=n1\n",
    "                mmax=i\n",
    "        return [mmax,n1max]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        a=[sum(i) for i in mat]\n",
    "        for i in range(len(a)):\n",
    "            if a[i]==max(a):\n",
    "                return [i,a[i]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        array = [0, 0]\n",
    "        for col in range(len(mat)):\n",
    "            if mat[col].count(1) > array[1]:\n",
    "                array = [col, mat[col].count(1)]\n",
    "        return array"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        res = 0\n",
    "        cnt = 0\n",
    "        for i, row in enumerate(mat):\n",
    "            c = row.count(1)\n",
    "            if c > cnt:\n",
    "                cnt = c\n",
    "                res = i\n",
    "            # print(res, cnt, c)\n",
    "                \n",
    "        return [res, mat[res].count(1)]\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        result= [0, 0]\n",
    "        for i in range(len(mat)):\n",
    "            temp1 = sum(mat[i])\n",
    "            if temp1 > result[1]:\n",
    "                result[1] = temp1\n",
    "                result[0] = i\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        ans = [0, 0]\n",
    "        for i in range(len(mat)):\n",
    "            cnt = mat[i].count(1)\n",
    "            if cnt > ans[1]:\n",
    "                ans = [i, cnt]\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        res = -1\n",
    "        idx = 0\n",
    "        for i, row in enumerate(mat):\n",
    "            a = sum(row)\n",
    "            if a > res:\n",
    "                res = a\n",
    "                idx = i\n",
    "        return [idx, res]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        m = len(mat)\n",
    "        n = len(mat[0])\n",
    "        maxx = -1\n",
    "        maxnum = -1\n",
    "\n",
    "        for i in range(m):\n",
    "            ans = 0\n",
    "            for j in range(n):\n",
    "                ans += mat[i][j]\n",
    "                if ans > maxnum:\n",
    "                    maxx = i\n",
    "                    maxnum  = ans\n",
    "        return [maxx, maxnum]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        if mat==[[0]]:\n",
    "            return [0,0]\n",
    "        if mat==[[1]]:\n",
    "            return [0,1]\n",
    "        m,v=0,0\n",
    "        for i in range(len(mat)):\n",
    "            k=0\n",
    "            for j in range(len(mat[0])):\n",
    "                if mat[i][j]==1:\n",
    "                    k+=1\n",
    "            if k>v:\n",
    "                m,v=i,k\n",
    "            k=0\n",
    "        return [m,v]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        num = [0] * 2\n",
    "        n = len(mat)\n",
    "        for row in range(n):\n",
    "            ans = mat[row].count(1)\n",
    "            if ans > num[1]:\n",
    "                num[1] = ans\n",
    "                num[0] = row\n",
    "        return num\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        m, n = 0, 0\n",
    "        nums_2 = 0\n",
    "        answer = 0\n",
    "        list_1 = []\n",
    "        for i in range(len(mat)):\n",
    "            nums_1 = 0\n",
    "            l = list(mat[i])\n",
    "            for s in range(len(l)):\n",
    "                if mat[i][s] == 1:\n",
    "                    nums_1 += 1\n",
    "            if nums_1 > nums_2:\n",
    "                nums_2 = nums_1\n",
    "                answer = i\n",
    "            elif nums_1 == nums_2:\n",
    "                nums_2 = nums_1\n",
    "        list_1.append(answer)\n",
    "        list_1.append(nums_2)\n",
    "\n",
    "        return list_1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        id,max_cnt = 0,0\n",
    "        m ,n = len(mat),len(mat[0])\n",
    "        for i,row in enumerate(mat):\n",
    "            cnt = sum(x == 1 for x in row)\n",
    "            if cnt > max_cnt:\n",
    "                id = i\n",
    "                max_cnt = cnt\n",
    "        return [id,max_cnt]\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        r, m = 0, 0\n",
    "        for i, j in enumerate(mat):\n",
    "            n = j.count(1)\n",
    "            if n > m:\n",
    "                r, m = i, n\n",
    "        return r, m"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        array = []\n",
    "        for col in mat:\n",
    "            array.append(col.count(1))\n",
    "        return [array.index(max(array)), max(array)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        ct, idx = 0, 0\n",
    "        for i, m in enumerate(mat):\n",
    "            s = sum(m)\n",
    "            if s > ct:\n",
    "                ct = s\n",
    "                idx = i\n",
    "        return [idx, ct]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        idx,res = 0,0\n",
    "        for i in range(len(mat)):\n",
    "            temp = sum(mat[i])\n",
    "            if temp > res:\n",
    "                idx = i\n",
    "                res = temp\n",
    "        return [idx,res]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        row = 0\n",
    "        ones = 0\n",
    "\n",
    "        for i in range(len(mat)):\n",
    "            tmp = 0\n",
    "            for num in mat[i]:\n",
    "                tmp += num\n",
    "            if tmp > ones:\n",
    "                ones = tmp\n",
    "                row = i\n",
    "\n",
    "        return [row, ones]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        nums = -1\n",
    "        index = -1\n",
    "        \n",
    "        rowLen = len(mat)\n",
    "        colLen = len(mat[0])\n",
    "\n",
    "        for i in range(rowLen):\n",
    "            temp = 0\n",
    "            for j in range(colLen):\n",
    "                temp += mat[i][j]\n",
    "            if temp > nums:\n",
    "                nums = temp\n",
    "                index = i\n",
    "        \n",
    "        return [index, nums]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        m = 0\n",
    "        ans = 0\n",
    "        for i in range(len(mat)):\n",
    "            curr = sum(mat[i])\n",
    "            if curr > m:\n",
    "                m = curr\n",
    "                ans = i\n",
    "        return [ans, m]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        idx = -1\n",
    "        max_one = -1\n",
    "        for i, row in enumerate(mat):\n",
    "            if (t := sum(row)) > max_one:\n",
    "                max_one = t\n",
    "                idx = i\n",
    "        return [idx, max_one]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        count=[]\n",
    "        for i in mat:\n",
    "            count.append(i.count(1))\n",
    "        maxnum=max(count)\n",
    "        j=count.index(maxnum)\n",
    "        return [j,maxnum]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        x=[[i,j.count(1)] for i,j in enumerate(mat)]\n",
    "        x=sorted(x,key=lambda x:(-x[1],x[0]))\n",
    "        return x[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\r\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\r\n",
    "        ans = [0,0]\r\n",
    "        for i,j in enumerate(mat):\r\n",
    "            if j.count(1) > ans[1]:\r\n",
    "                ans = [i,j.count(1)]\r\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        max_sum, idx = -1, 0\n",
    "        for i, row in enumerate(mat):\n",
    "            s = sum(row)\n",
    "            if s > max_sum:\n",
    "                max_sum, idx = s, i\n",
    "        return [idx, max_sum]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        idx = 0\n",
    "        sums = 0\n",
    "        for i ,row in enumerate(mat):\n",
    "            s = sum(row)\n",
    "            if s >sums:\n",
    "                sums = s\n",
    "                idx = i\n",
    "        return [idx, sums]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        array = [0, 0]\n",
    "        for col in range(len(mat)):\n",
    "            if mat[col].count(1) > array[1]:\n",
    "                array = [col, mat[col].count(1)]\n",
    "        return array"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        idx = maxv = 0\n",
    "        for i, row in enumerate(mat):\n",
    "            x = Counter(row)[1]\n",
    "            if x > maxv:\n",
    "                maxv = x\n",
    "                idx = i\n",
    "        return [idx, maxv]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        array = []\n",
    "        for col in mat:\n",
    "            array.append(col.count(1))\n",
    "        return [array.index(max(array)), max(array)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        ans = [0,0]\n",
    "        for i,row in enumerate(mat):\n",
    "            if sum(row) > ans[1]:\n",
    "                ans[1] = sum(row)\n",
    "                ans[0] = i\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        max_sum, idx = -1, 0\n",
    "        for i, row in enumerate(mat):\n",
    "            s = sum(row)\n",
    "            if s > max_sum:\n",
    "                max_sum, idx = s, i\n",
    "        return [idx, max_sum]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        n=len(mat)\n",
    "        sum_=0\n",
    "        idx=0\n",
    "        for i in range(n):\n",
    "            s=sum(mat[i])\n",
    "            if s>sum_:\n",
    "                sum_=s\n",
    "                idx=i\n",
    "        return [idx,sum_]\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        res = [0,0]\n",
    "        for i in range(len(mat)):\n",
    "            if mat[i].count(1)>res[1]:\n",
    "                res[1] = mat[i].count(1)\n",
    "                res[0] = i\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        max_sum, idx = -1, 0\n",
    "        for i, row in enumerate(mat):\n",
    "            s = sum(row)\n",
    "            if s > max_sum:\n",
    "                max_sum, idx = s, i\n",
    "        return [idx, max_sum]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        max_val=0\n",
    "        ans=0\n",
    "        m=len(mat)\n",
    "        for i in range(m):\n",
    "            cnt=0\n",
    "            for j in mat[i]:\n",
    "                if j==1:\n",
    "                    cnt+=1\n",
    "            if cnt>max_val:\n",
    "                max_val=cnt\n",
    "                ans=i\n",
    "        return ans,max_val\n",
    "\n",
    "            \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        res = [0, -1]\n",
    "        for i in range(len(mat)):\n",
    "            sumv = 0\n",
    "            for j in range(len(mat[0])):\n",
    "                if mat[i][j] == 1:\n",
    "                    sumv += 1\n",
    "            if sumv > res[1]:\n",
    "                res[1] = sumv\n",
    "                res[0] = i\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        idx,cnt = -1,-1\n",
    "        for i,row in enumerate(mat):\n",
    "            c = row.count(1)\n",
    "            if c > cnt:\n",
    "                idx = i\n",
    "                cnt = c\n",
    "        return [idx,cnt]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        s = [sum(line) for line in mat]\n",
    "        return [s.index(max(s)),max(s)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        n = len(mat)\n",
    "        a, s = 0, 0\n",
    "        for i in range(n):\n",
    "            if mat[i].count(1) > s:\n",
    "                s = mat[i].count(1)\n",
    "                a = i\n",
    "        return [a, s]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        m, n = len(mat), len(mat[0])\n",
    "        res = [0,0]\n",
    "\n",
    "        for i in range(m):\n",
    "            tmp = mat[i].count(1) \n",
    "            if tmp > res[1]:\n",
    "                res = [i, tmp]\n",
    "        return res\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        cnt=0\n",
    "        m=len(mat)\n",
    "        idx=0\n",
    "        for i,row in enumerate(mat):\n",
    "            c=sum(row)\n",
    "            if c>cnt:\n",
    "                cnt=c\n",
    "                idx=i  \n",
    "        return [idx,cnt]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self,mat:List[List[int]]) ->List[int]:\n",
    "        max_sum,idx= -1,0\n",
    "        for i,row in enumerate(mat):\n",
    "            s = sum(row)\n",
    "            if s > max_sum:\n",
    "                max_sum,idx = s,i\n",
    "        return [idx,max_sum]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        max_sum, idx = -1, 0\n",
    "        for i, row in enumerate(mat):\n",
    "            s = sum(row)\n",
    "            if s > max_sum:\n",
    "                max_sum, idx = s, i\n",
    "        return [idx, max_sum]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        max_sum, idx = -1, 0\n",
    "        for i, row in enumerate(mat):\n",
    "            s = sum(row)\n",
    "            if s > max_sum:\n",
    "                max_sum, idx = s, i\n",
    "        return [idx, max_sum]\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        max_sum, idx = -1, 0\n",
    "        for i, row in enumerate(mat):\n",
    "            s = sum(row)\n",
    "            if s > max_sum:\n",
    "                max_sum, idx = s, i\n",
    "        return [idx, max_sum]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        max_sum, idx = -1, 0\n",
    "        for i, row in enumerate(mat):\n",
    "            s = sum(row)\n",
    "            if s > max_sum:\n",
    "                max_sum, idx = s, i\n",
    "        return [idx, max_sum]\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        return max([(v[0], sum(v[1])) for v in enumerate(mat)], key=lambda v: v[1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        max_sum, idx = -1, 0\n",
    "        for i, row in enumerate(mat):\n",
    "            s = sum(row)\n",
    "            if s > max_sum:\n",
    "                max_sum, idx = s, i\n",
    "        return [idx, max_sum]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:\n",
    "        m=len(mat)\n",
    "        cnt=[]\n",
    "        for i in range(m):\n",
    "            cnt.append([i,0]) \n",
    "        for i in range(m):\n",
    "            for j in range(len(mat[0])):\n",
    "                if mat[i][j] == 1:\n",
    "                    cnt[i][1]+=1\n",
    "        cnt.sort(key=lambda x:(x[1],-x[0]),reverse=True)\n",
    "        return cnt[0]"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
